package com.hxzy.service.impl;

import com.hxzy.util.MybatisUtil;
import com.hxzy.dto.ResourceStoreDTO;
import com.hxzy.entity.ResourceStore;
import com.hxzy.mapper.ResourceStoreMapper;
import com.hxzy.service.ResourceStoreService;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lqq
 * @Description:
 * @Date: 2022/3/8 17:12
 */
public class ResourceStoreSeviceImpl implements ResourceStoreService {
    @Override
    public int insert(ResourceStore resourceStore) {
        int count=0;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            ResourceStoreMapper mapper = sqlSession.getMapper(ResourceStoreMapper.class);
           count= mapper.insert(resourceStore);
           sqlSession.commit();
        }
        return count;
    }

    @Override
    public int update(ResourceStore resourceStore) {
        int count=0;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            ResourceStoreMapper mapper = sqlSession.getMapper(ResourceStoreMapper.class);
            count= mapper.update(resourceStore);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public int delete(String resId) {
        int count=0;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            ResourceStoreMapper mapper = sqlSession.getMapper(ResourceStoreMapper.class);
            count= mapper.delete(resId);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public ResourceStore findOne(String resId) {
        ResourceStore resourceStore=null;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            ResourceStoreMapper mapper = sqlSession.getMapper(ResourceStoreMapper.class);
           resourceStore= mapper.findOne(resId);
        }
        return resourceStore;
    }

    @Override
    public List<ResourceStore> search(ResourceStoreDTO resourceStoreDTO) {
        List<ResourceStore> list=new ArrayList<>();
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            ResourceStoreMapper mapper = sqlSession.getMapper(ResourceStoreMapper.class);
            list= mapper.search(resourceStoreDTO);
        }
        return list;
    }
}
